﻿using System;
using System.ComponentModel;
using System.Windows;
using Vkontakte.Api;

namespace VkClientIM.Logic
{
	public class Profile
		: INotifyPropertyChanged, IComparable<Profile>,IComparable
	{
		#region Поля
		private long _userID;
		private string _firstName = "";
		private string _lastName = "";
		private string _nickName = "";
		private byte[] _photo;
		private string _activity = "";
		private string _domain = "";
		private int _online;
		private string _photoBig;
		private string _photoRec;
		#endregion

		public Profile() {}

		public Profile(long userID)
		{
			_userID = userID;
		}

		#region Свойства
		public long UserID
		{
			get { return _userID; }
			set 
			{
				if (_userID != value)
				{
					_userID = value;
					if (PropertyChanged!=null)
					{
						PropertyChanged(this, new PropertyChangedEventArgs("UserID"));
					}
				}
			}
		}
		public string FirstName
		{
			get { return _firstName; }
			set
			{
				if (_firstName!=value)
				{
					_firstName = value ?? "";
					if (PropertyChanged != null)
					{
						PropertyChanged(this, new PropertyChangedEventArgs("FirstName"));
					}
				}
			}
		}
		public string NickName
		{
			get { return _nickName; }
			set
			{
				if (_nickName != value)
				{
					_nickName = value ?? "";
					if (PropertyChanged != null)
					{
						PropertyChanged(this, new PropertyChangedEventArgs("NickName"));
					}
				}
			}
		}
		public string LastName
		{
			get { return _lastName; }
			set
			{
				if (_lastName != value)
				{
					_lastName = value ?? "";
					if (PropertyChanged != null)
					{
						PropertyChanged(this, new PropertyChangedEventArgs("LastName"));
					}
				}
			}
		}
		public byte[] Photo
		{
			get { return _photo; }
			set
			{
				_photo = value;
				if (PropertyChanged != null)
				{
					PropertyChanged(this, new PropertyChangedEventArgs("Photo"));
				}
			}
		}
		public string Domain
		{
			get { return _domain; }
			set
			{
				if (_domain != value)
				{
					_domain = value;
					if (PropertyChanged != null)
					{
						PropertyChanged(this, new PropertyChangedEventArgs("Domain"));
					}
				}
			}
		}
		public string Activity
		{
			get { return _activity; }
			set
			{
				if (_activity != value)
				{
					_activity = value ?? "";
					if (PropertyChanged != null)
					{
						PropertyChanged(this, new PropertyChangedEventArgs("Activity"));
					}
				}
			}
		}

		public string PhotoRec
		{
			get { return _photoRec; }
			set
			{
				if (_photoRec != value)
				{
					_photoRec = value;
					if (PropertyChanged != null)
					{
						PropertyChanged(this, new PropertyChangedEventArgs("ImageRec"));
					}
				}
			}
		}

		public string PhotoBig
		{
			get { return _photoBig; }
			set
			{
				if (_photoBig != value)
				{
					_photoBig = value;
					if (PropertyChanged != null)
					{
						PropertyChanged(this, new PropertyChangedEventArgs("ImageBig"));
					}
				}
			}
		}

		public int Online
		{
			get { return _online; }
			set
			{
				if (_online != value)
				{
					_online = value;
					if (PropertyChanged != null)
					{
						PropertyChanged(this, new PropertyChangedEventArgs("Online"));
					}
				}
			}
		}
		#endregion

		public event PropertyChangedEventHandler PropertyChanged;

		public int CompareTo(Profile other)
		{
			return -(this.Online - other.Online) * 1000 + string.Compare(this.FirstName, other.FirstName);
		}

		public int CompareTo(object obj)
		{
			if (obj is Profile)
			{
				return this.CompareTo((Profile) obj);
			}
			return 0;
		}
	}
}